package cn.edu.neusoft.wuguangsheng.market.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.activity.OrderFoodsActivity;
import cn.edu.neusoft.wuguangsheng.market.bean.OrderFoodResut;

/**
 * Created by little on 2018/4/21.
 */

public class showOrderAdapter extends BaseAdapter<OrderFoodResut> {
    public showOrderAdapter(Context context, List<OrderFoodResut> items, int layoutResource){
        super(context, items, layoutResource);
    }

     //List<OrderFoodInfo> itemsss;
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context)
                .inflate(layoutResourse,parent,false);
        OrderViewHolder cartViewHolder=new OrderViewHolder(itemView);
        return cartViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        OrderViewHolder cartViewHolder=(OrderViewHolder) holder;
        OrderFoodResut orderFoodResut=items.get(position);
        final  String orid=orderFoodResut.getOrid();
        cartViewHolder.dd_orid.setText("订单号:"+orid);
        final String time= orderFoodResut.getOrdertime();
        cartViewHolder.dd_time.setText("下单时间:"+time);
        final String mrid=orderFoodResut.getMrid();
        final String flag=orderFoodResut.getFlag();
        final String num=orderFoodResut.getHc();
        cartViewHolder.dd_num.setText("菜品数量:"+num);
        final double allsuma=orderFoodResut.getAllprice();
        String allsum=String.valueOf(allsuma);
        cartViewHolder.dd_allprice.setText("总计:"+allsum);
        if(flag.equals("0")){
            String a="已付款";
            cartViewHolder.dd_flag.setText("状态:"+a);
        }
        else if(flag.equals("1")){
            String a="已捡货";
            cartViewHolder.dd_flag.setText("状态:"+a);
        }
        else if(flag.equals("2")){
            String a="已发货";
            cartViewHolder.dd_flag.setText("状态:"+a);
        }
        else if(flag.equals("3")){
                String a="已签收";
                cartViewHolder.dd_flag.setText("状态:"+a);
        }
        else if(flag.equals("4")){
            String a="已完成";
            cartViewHolder.dd_flag.setText("状态:"+a);
        }
        else{
            String a="订单异常";
            cartViewHolder.dd_flag.setText("状态:"+a);
        }
        Picasso.with(context).load(items.get(position).getPic()).resize(60,60).centerCrop().into(cartViewHolder.dd_img);

        cartViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent1 = new Intent(context, OrderFoodsActivity.class);
                intent1.putExtra("orid",orid);
                intent1.putExtra("mrid",mrid);
                context.startActivity(intent1);
            }
        });
    }
}
